<!DOCTYPE html>
<html>
    <head>
        <title>UserRead</title>
        <meta charset="UTF-8">
        <meta name="viewport" content="width=device-width, initial-scale=1.0">
        <script src="__PUBLIC__/jquery-3.0.0.js"></script>
        <style type="text/css">
            #box{
                width: 1000px;
                text-align: center;
                margin: 0 auto;
                padding: 0;
            }
            #skip{
                text-decoration: none;
            }
            #body{
                text-align:start;
                width: 180px;
                margin: 0 auto;
            }
            .skip{
                text-decoration: none;
            }
            span{
                color: #bbb;
            }
            a{
                text-decoration:none;
            }
        </style>
    </head>
    <body>
        <div id="box">
            <h2>用户资料</h2>
            <br/><br/>
            <table id="body">
                <tr>
                    <td>
                       用户ID： <?php echo $list['id']?>
                    </td>
                </tr>
                <tr>
                    <td>
                       用户名： <?php echo $list['name']?>
                    </td>
                </tr>
                <tr>
                    <td>
                        权限：<select id="role" name="role">
                                <option value="0" <?php  if(0==$list['role']){?> selected="selected"  <?php }?> >普通用户</option>
                                <option value="1" <?php  if(1==$list['role']){?> selected="selected"  <?php }?> >管理员</option>
                             </select>
                    </td>
                </tr>
                <tr>
                    <td>
                       Email： <?php echo $list['email']?>
                    </td>
                </tr>
                <tr>
                    <td>
                       贡献值：<?php echo $list['contribution'] ?> 
                    </td>
                </tr>
            </table>
            <br/><p id="p"></p><br/>
            <button id='save'>保存</button>&nbsp;&nbsp;<button id='delete'>删除用户</button>
        </div>
        <script>
            $("#save").click(function(){
                var pass = prompt('请输入您的密码');
                var url = "<?php echo U('Admin/Admin/usersave?id='.$list['id'])?>";
                var data= {};
                data ['role'] = $('#role').val();
                data ['pass'] = pass;
                var dataType = "json";
                $.post(
                    url,
                    data,
                    function(data){                      
                        if(data.status === 1){
                            alert('保存成功！');
                            location.href="<?php echo U('Admin/Admin/center')?>";
                        }
                        if(data.status === 0){
                            $("#p").html("*密码错误！").css("color","red");
                        }
                        if(data.status === 2){
                            $("#p").html("*请先登录！").css("color","red");
                        }
                    },
                    dataType
                );
               return false; 
            }        
        );
            $("#delete").click(function(){
                var affirm = confirm('确定删除用户么？');
                if(affirm == true){
                    var affirm = confirm('*警告：用户数据删除将不可恢复，是否继续？');
                    if(affirm == true){    
                        var pass = prompt('请输入您的密码');
                        var url = "<?php echo U('Admin/Admin/delete?id='.$list['id'])?>";
                        var data= {}; 
                        data ['pass'] = pass;
                        var dataType = "json";
                        $.post(
                            url,
                            data,
                            function(data){                      
                                if(data.status === 1){
                                    alert('删除成功！');
                                    location.href="<?php echo U('Admin/Admin/center')?>";
                                }
                                if(data.status === 0){
                                    $("#p").html("*密码错误！").css("color","red");
                                }
                                if(data.status === 2){
                                    $("#p").html("*请先登录！").css("color","red");
                                }
                            },
                            dataType
                        );
                       return false;
                    }
                }
            }        
        );
        </script>
    </body>
</html>
